import { createRouter, createWebHistory } from 'vue-router'
import Index from '../pages/Index.vue'

const routes = [{
        path: '/',
        redirect: '/index',
        component: Index,
        meta: { title: '首页' },
        children: [{
                path: 'index',
                name: 'index',
                component: () =>
                    import ('../pages/subpages/Index.vue'),
                meta: { title: '首页' }
            },
            {
                path: 'goods/:id',
                name: 'goods',
                component: () =>
                    import ('../pages/subpages/Goods.vue'),
                meta: { title: '商品详情' }
            },
            {
                path: 'good',
                name: 'good',
                component: () =>
                    import ('../pages/subpages/Good.vue'),
                meta: { title: '商品详情' }
            },
            {
                path: 'product/:id',
                name: 'productDetail',
                component: () =>
                    import ('../pages/subpages/GoodsDetail.vue'),
                props: true,
                meta: { title: '商品详情' }
            },
            {
                path: 'cart',
                name: 'cart',
                component: () =>
                    import ('../pages/subpages/Cart.vue'),
                meta: { title: '购物车' }
            }
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ('../pages/login.vue'),
        meta: { title: '登录' }
    },
    {
        path: '/register',
        name: 'register',
        component: () =>
            import ('../pages/register.vue'),
        meta: { title: '注册' }
    },
    {
        path: '/profile',
        name: 'profile',
        component: () =>
            import ('../pages/Profile.vue'),
        meta: { title: '个人主页' }
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

export default router